﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using NewDDSys.Entity;
using NewDDSys.IBLL;
using NewDDSys.IDAL;
using NewDDSys.Factory;
using NewDDSys.Utility;
using AjaxControlToolkit;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Web_LTRJH : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public void ddlKu_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlKu.SelectedIndex != 0 && ddlKu.SelectedValue.ToString() != "嘉东库")
        {
            DataSet ds1 = BLLFactory.CreateLtrBLL().JHRQFW(ddlKu.SelectedValue.ToString(), txtJday.Text.ToString());
            if (ds1.Tables[0].Rows.Count != 0)
            {
                string sday = ds1.Tables[0].Rows[0]["sday"].ToString();
                txtSday.Text = Convert.ToDateTime(sday).ToShortDateString();
                txtSday.Attributes["contentEditable"] = "false";
                string eday = ds1.Tables[0].Rows[0]["eday"].ToString();
                txtEday.Text = Convert.ToDateTime(eday).ToShortDateString();
                txtEday.Attributes["contentEditable"] = "false";
                TimeSpan ts = Convert.ToDateTime(txtEday.Text.ToString()) - Convert.ToDateTime(txtSday.Text.ToString());
                int jhzq = Convert.ToInt32(ts.TotalDays);
                txtZQ.Text = Convert.ToString(jhzq + 1);
                txtZQ.Attributes["contentEditable"] = "false";
                txtYJH.Text = BLLFactory.CreateLtrBLL().JHS(ddlKu.SelectedValue.ToString(), txtSday.Text.ToString(), txtEday.Text.ToString());
                txtYJH.Attributes["contentEditable"] = "false";
                DataSet ds3 = BLLFactory.CreateLtrBLL().JHRQ(ddlKu.SelectedValue.ToString(), txtSday.Text.ToString(), txtEday.Text.ToString());
                if (ds3.Tables[0].Rows.Count != 0)
                {
                    string rqjl = "";
                    for (int i = 0; i < ds3.Tables[0].Rows.Count; i++)
                    {
                        string rq = ds3.Tables[0].Rows[i][0].ToString();
                        rqjl = rqjl + Convert.ToDateTime(rq).Date.ToString() + "、";


                    }
                    txtRQ.Text = rqjl;
                    txtRQ.Attributes["contentEditable"] = "false";
                }
                decimal zl = Convert.ToDecimal(BLLFactory.CreateLtrBLL().ZJHL(ddlKu.SelectedValue.ToString(), txtSday.Text.ToString(), txtEday.Text.ToString()));
                decimal yjh = 0;
                string jhl = BLLFactory.CreateLtrBLL().YJHL(ddlKu.SelectedValue.ToString(), txtSday.Text.ToString(), txtEday.Text.ToString());
                if (jhl != "")
                    yjh = Convert.ToDecimal(jhl);


                txtWF.Text = Convert.ToString(zl - yjh);
                txtWF.Attributes["contentEditable"] = "false";
                decimal xjh = Convert.ToDecimal(txtZQ.Text.ToString()) - Convert.ToDecimal(txtYJH.Text.ToString());
                txtJY.Text = (Convert.ToDecimal(txtWF.Text.ToString()) / xjh).ToString("f2");
                txtJY.Attributes["contentEditable"] = "false";
            }




        }
        else if (ddlKu.SelectedValue.ToString() == "嘉东库")
        {
            ddlPZ.Visible = true;
            UpdatePanel1.Visible = false;
            UpdatePanel3.Visible = true;
        }
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        int checkValue = 0;
        LtrInfo jh = new LtrInfo();
        if (ddlKu.SelectedValue.ToString() == "嘉东库")
        {
            switch (ddlPZ.SelectedValue.ToString())
            {
                case "线材":
                    jh.Ku = "嘉东线材"; break;
                case "螺纹":
                    jh.Ku = "嘉东螺纹"; break;
                case "卷板":
                    jh.Ku = "嘉东卷板"; break;
                case "板材":
                    jh.Ku = "嘉东板材"; break;
                default:
                    break;
            }
        }
        else
        {
            jh.Ku = ddlKu.SelectedValue.ToString();
        }
        jh.Jday = txtJday.Text.ToString();
        jh.Yl = Convert.ToInt32(txtYL.Text.ToString());
        jh.Xday = DateTime.Now.ToShortDateString().ToString();
        jh.Num = BLLFactory.CreateLtrBLL().AUTOID(ddlKu.SelectedValue.ToString());
        checkValue = BLLFactory.CreateLtrBLL().Add(jh);
        if (checkValue >= 1)
        {
            Response.Write(" <script   language=javascript> window.alert( ' 提交成功！ ');</script> ");
        }
        Response.Redirect("LTRJL.aspx");
    }
    protected void btnRepeat_Click(object sender, EventArgs e)
    {
        ddlKu.SelectedIndex = 0;
        txtJday.Text = "";
        txtYL.Text = "";
    }
    public void ddlPZ_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlPZ.SelectedIndex != 0)
        {
            switch (ddlPZ.SelectedValue.ToString())
            {
                case "线材":
                    {
                        DataSet ds1 = BLLFactory.CreateLtrBLL().XCRQFW(txtJday.Text.ToString());
                        if (ds1.Tables[0].Rows.Count != 0)
                        {
                            string sday = ds1.Tables[0].Rows[0]["sday"].ToString();
                            txtSday2.Text = Convert.ToDateTime(sday).ToShortDateString();
                            txtSday2.Attributes["contentEditable"] = "false";
                            string eday = ds1.Tables[0].Rows[0]["eday"].ToString();
                            txtEday2.Text = Convert.ToDateTime(eday).ToShortDateString();
                            txtEday2.Attributes["contentEditable"] = "false";
                            TimeSpan ts = Convert.ToDateTime(txtEday2.Text.ToString()) - Convert.ToDateTime(txtSday2.Text.ToString());
                            int jhzq = Convert.ToInt32(ts.TotalDays);
                            txtZQ2.Text = Convert.ToString(jhzq + 1);
                            txtZQ2.Attributes["contentEditable"] = "false";
                            txtYJH2.Text = BLLFactory.CreateLtrBLL().XCYJHTS(txtSday2.Text.ToString(), txtEday2.Text.ToString());
                            txtYJH2.Attributes["contentEditable"] = "false";
                            DataSet ds3 = BLLFactory.CreateLtrBLL().XCJHRQ(txtSday2.Text.ToString(), txtEday2.Text.ToString());
                            if (ds3.Tables[0].Rows.Count != 0)
                            {
                                string rqjl = "";
                                for (int i = 0; i < ds3.Tables[0].Rows.Count; i++)
                                {
                                    string rq = ds3.Tables[0].Rows[i][0].ToString();
                                    rqjl = rqjl + Convert.ToDateTime(rq).Date.ToString() + "、";


                                }
                                txtRQ2.Text = rqjl;
                                txtRQ2.Attributes["contentEditable"] = "false";
                            }
                            decimal zl = Convert.ToDecimal(BLLFactory.CreateLtrBLL().XCZJH(txtSday2.Text.ToString(), txtEday2.Text.ToString()));
                            decimal yjh = 0;
                            string jhl = BLLFactory.CreateLtrBLL().XCYJH(txtSday2.Text.ToString(), txtEday2.Text.ToString());
                            if (jhl != "")
                                yjh = Convert.ToDecimal(jhl);


                            txtWF2.Text = Convert.ToString(zl - yjh);
                            txtWF2.Attributes["contentEditable"] = "false";
                            decimal xjh = Convert.ToDecimal(txtZQ2.Text.ToString()) - Convert.ToDecimal(txtYJH2.Text.ToString());
                            txtJY2.Text = (Convert.ToDecimal(txtWF.Text.ToString()) / xjh).ToString("f2");
                            txtJY2.Attributes["contentEditable"] = "false";
                        }



                    }; break;
                case "螺纹":
                    {
                        DataSet ds1 = BLLFactory.CreateLtrBLL().BCRQFW(txtJday.Text.ToString());
                        if (ds1.Tables[0].Rows.Count != 0)
                        {
                            string sday = ds1.Tables[0].Rows[0]["sday"].ToString();
                            txtSday2.Text = Convert.ToDateTime(sday).ToShortDateString();
                            txtSday2.Attributes["contentEditable"] = "false";
                            string eday = ds1.Tables[0].Rows[0]["eday"].ToString();
                            txtEday2.Text = Convert.ToDateTime(eday).ToShortDateString();
                            txtEday2.Attributes["contentEditable"] = "false";
                            TimeSpan ts = Convert.ToDateTime(txtEday2.Text.ToString()) - Convert.ToDateTime(txtSday2.Text.ToString());
                            int jhzq = Convert.ToInt32(ts.TotalDays);
                            txtZQ2.Text = Convert.ToString(jhzq + 1);
                            txtZQ2.Attributes["contentEditable"] = "false";
                            txtYJH2.Text = BLLFactory.CreateLtrBLL().BCYJHTS(txtSday2.Text.ToString(), txtEday2.Text.ToString());
                            txtYJH2.Attributes["contentEditable"] = "false";
                            DataSet ds3 = BLLFactory.CreateLtrBLL().BCJHRQ(txtSday2.Text.ToString(), txtEday2.Text.ToString());
                            if (ds3.Tables[0].Rows.Count != 0)
                            {
                                string rqjl = "";
                                for (int i = 0; i < ds3.Tables[0].Rows.Count; i++)
                                {
                                    string rq = ds3.Tables[0].Rows[i][0].ToString();
                                    rqjl = rqjl + Convert.ToDateTime(rq).Date.ToString() + "、";


                                }
                                txtRQ2.Text = rqjl;
                                txtRQ2.Attributes["contentEditable"] = "false";
                            }
                            decimal zl = Convert.ToDecimal(BLLFactory.CreateLtrBLL().BCZJH(txtSday2.Text.ToString(), txtEday2.Text.ToString()));
                            decimal yjh = 0;
                            string jhl = BLLFactory.CreateLtrBLL().BCYJH(txtSday2.Text.ToString(), txtEday2.Text.ToString());
                            if (jhl != "")
                                yjh = Convert.ToDecimal(jhl);


                            txtWF2.Text = Convert.ToString(zl - yjh);
                            txtWF2.Attributes["contentEditable"] = "false";
                            decimal xjh = Convert.ToDecimal(txtZQ2.Text.ToString()) - Convert.ToDecimal(txtYJH2.Text.ToString());
                            txtJY2.Text = (Convert.ToDecimal(txtWF2.Text.ToString()) / xjh).ToString("f2");
                            txtJY2.Attributes["contentEditable"] = "false";
                        }


                    }; break;
                case "卷板":
                    {
                        DataSet ds1 = BLLFactory.CreateLtrBLL().JBRQFW(txtJday.Text.ToString());
                        if (ds1.Tables[0].Rows.Count != 0)
                        {
                            string sday = ds1.Tables[0].Rows[0]["sday"].ToString();
                            txtSday2.Text = Convert.ToDateTime(sday).ToShortDateString();
                            txtSday2.Attributes["contentEditable"] = "false";
                            string eday = ds1.Tables[0].Rows[0]["eday"].ToString();
                            txtEday2.Text = Convert.ToDateTime(eday).ToShortDateString();
                            txtEday2.Attributes["contentEditable"] = "false";
                            TimeSpan ts = Convert.ToDateTime(txtEday2.Text.ToString()) - Convert.ToDateTime(txtSday2.Text.ToString());
                            int jhzq = Convert.ToInt32(ts.TotalDays);
                            txtZQ2.Text = Convert.ToString(jhzq + 1);
                            txtZQ2.Attributes["contentEditable"] = "false";
                            txtYJH2.Text = BLLFactory.CreateLtrBLL().JBYJHTS(txtSday2.Text.ToString(), txtEday2.Text.ToString());
                            txtYJH2.Attributes["contentEditable"] = "false";
                            DataSet ds3 = BLLFactory.CreateLtrBLL().JBJHRQ(txtSday2.Text.ToString(), txtEday2.Text.ToString());
                            if (ds3.Tables[0].Rows.Count != 0)
                            {
                                string rqjl = "";
                                for (int i = 0; i < ds3.Tables[0].Rows.Count; i++)
                                {
                                    string rq = ds3.Tables[0].Rows[i][0].ToString();
                                    rqjl = rqjl + Convert.ToDateTime(rq).Date.ToString() + "、";


                                }
                                txtRQ2.Text = rqjl;
                                txtRQ2.Attributes["contentEditable"] = "false";
                            }
                            decimal zl = Convert.ToDecimal(BLLFactory.CreateLtrBLL().JBZJH(txtSday2.Text.ToString(), txtEday2.Text.ToString()));
                            decimal yjh = 0;
                            string jhl = BLLFactory.CreateLtrBLL().JBYJH(txtSday2.Text.ToString(), txtEday2.Text.ToString());
                            if (jhl != "")
                                yjh = Convert.ToDecimal(jhl);


                            txtWF2.Text = Convert.ToString(zl - yjh);
                            txtWF2.Attributes["contentEditable"] = "false";
                            decimal xjh = Convert.ToDecimal(txtZQ2.Text.ToString()) - Convert.ToDecimal(txtYJH2.Text.ToString());
                            txtJY2.Text = (Convert.ToDecimal(txtWF2.Text.ToString()) / xjh).ToString("f2");
                            txtJY2.Attributes["contentEditable"] = "false";
                        }


                    }; break;
                case "板材":
                    {
                        DataSet ds1 = BLLFactory.CreateLtrBLL().ZBRQFW(txtJday.Text.ToString());
                        if (ds1.Tables[0].Rows.Count != 0)
                        {
                            string sday = ds1.Tables[0].Rows[0]["sday"].ToString();
                            txtSday2.Text = Convert.ToDateTime(sday).ToShortDateString();
                            txtSday2.Attributes["contentEditable"] = "false";
                            string eday = ds1.Tables[0].Rows[0]["eday"].ToString();
                            txtEday2.Text = Convert.ToDateTime(eday).ToShortDateString();
                            txtEday2.Attributes["contentEditable"] = "false";
                            TimeSpan ts = Convert.ToDateTime(txtEday2.Text.ToString()) - Convert.ToDateTime(txtSday2.Text.ToString());
                            int jhzq = Convert.ToInt32(ts.TotalDays);
                            txtZQ2.Text = Convert.ToString(jhzq + 1);
                            txtZQ2.Attributes["contentEditable"] = "false";
                            txtYJH2.Text = BLLFactory.CreateLtrBLL().ZBYJHTS(txtSday2.Text.ToString(), txtEday2.Text.ToString());
                            txtYJH2.Attributes["contentEditable"] = "false";
                            DataSet ds3 = BLLFactory.CreateLtrBLL().ZBJHRQ(txtSday2.Text.ToString(), txtEday2.Text.ToString());
                            if (ds3.Tables[0].Rows.Count != 0)
                            {
                                string rqjl = "";
                                for (int i = 0; i < ds3.Tables[0].Rows.Count; i++)
                                {
                                    string rq = ds3.Tables[0].Rows[i][0].ToString();
                                    rqjl = rqjl + Convert.ToDateTime(rq).Date.ToString() + "、";


                                }
                                txtRQ2.Text = rqjl;
                                txtRQ2.Attributes["contentEditable"] = "false";
                            }
                            decimal zl = Convert.ToDecimal(BLLFactory.CreateLtrBLL().ZBZJH(txtSday2.Text.ToString(), txtEday2.Text.ToString()));
                            decimal yjh = 0;
                            string jhl = BLLFactory.CreateLtrBLL().ZBYJH(txtSday2.Text.ToString(), txtEday2.Text.ToString());
                            if (jhl != "")
                                yjh = Convert.ToDecimal(jhl);


                            txtWF2.Text = Convert.ToString(zl - yjh);
                            txtWF2.Attributes["contentEditable"] = "false";
                            decimal xjh = Convert.ToDecimal(txtZQ2.Text.ToString()) - Convert.ToDecimal(txtYJH2.Text.ToString());
                            txtJY2.Text = (Convert.ToDecimal(txtWF2.Text.ToString()) / xjh).ToString("f2");
                            txtJY2.Attributes["contentEditable"] = "false";
                        }

                    }; break;
                default:
                    break;
            }
        }
    }
}
